<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */

class Offline extends Base
{
	public function Offline()
	{
		$this->title = $GLOBALS['lang']->GetLanguage("Offline", "title");
		$this->toolbar = true;
		$this->moduleID = 600;
		$this->permission = GetPermission($this->moduleID);
		
		if(PermissionCount($this->permission) == 0)
		{
			$this->allowed = false;
		}
	}
	
	public function Add()
	{		
		
	}
	public function Edit()
	{		
		
	}
	
	public function AnalysPost()
	{
		if($_POST['action'] == "showWeek")
		{
			include("./_tables.php");
		
			echo 
			'<div id="cpanel">';
					
			$dgv = new DataGridView($this);
			$dgv->deleteButton = false;
			$dgv->editButton = false;
			
			
			$dgv->OpenHeader();
			$dgv->AddHeader("firstName", "10%", true);
			$dgv->AddHeader("lastName", "10%", true);
			$dgv->AddHeader("jobid", "10%", true);
			$dgv->AddHeader("jobname", "10%", true);
			$dgv->AddHeader("comment", "10%", true);
			$dgv->AddHeader("dayName", "10%", true);
			$dgv->AddHeader("start", "10%", true);
			$dgv->AddHeader("end", "10%", true);
			$dgv->AddHeader("week", "10%", true);
			$dgv->AddHeader("timeDiffMinus", "10%", true);
			$dgv->AddHeader("timeDiff", "10%", true);
			$dgv->CloseHeader();
			
			
			$query = "SELECT *, SEC_TO_TIME(SUM( TIME_TO_SEC( TIMEDIFF( (SELECT CASE WHEN endTime IS NULL THEN NOW() ELSE endTime END), startTime ) ) ) - 3240) AS timeDiff, SEC_TO_TIME(SUM( TIME_TO_SEC( TIMEDIFF( (SELECT CASE WHEN endTime IS NULL THEN NOW() ELSE endTime END), startTime ) ) )) AS timeD, DATE_FORMAT(startTime,'%a') as dayName, DATE_FORMAT(startTime,'%W') as dayName
			FROM ".$viewjobtimesweek." WHERE week=".$_POST['week'.$_POST['id']]."
			group by startTime";
			$res = $GLOBALS['db']->Query($query);
			
			
			$count = 0;
			while($line = $GLOBALS['db']->Fetch($res))
			{
				
				$dgv->AddRow($line->id);
				$dgv->AddData($line->firstName, "", "", "firstName");
				$dgv->AddData($line->lastName, "", "", "lastName");
				$dgv->AddData($line->jobID, "", "", "jobID");
				$dgv->AddData($line->jobname, "", "", "jobname");
				$dgv->AddData($line->comment, "", "", "commnt");
				$dgv->AddData($GLOBALS['lang']->GetLanguage("Date", $line->dayName), "", "", "dayName");
				$dgv->AddData($line->startD, "", "", "startD");
				$dgv->AddData($line->end, "", "", "street");
				$dgv->AddData($line->week, "", "", "week");
				$dgv->AddData($line->timeDiff, "", "", "timeDiff");
				$dgv->AddData($line->timeD, "", "", "timeD");
				$dgv->CloseRow();
				$count++;
			}
			
			$dgv->CloseDataGrid();
			
			echo '</div>';
		}
		else
		{
			$this->Paint();
		}
	}

	public function Paint()
	{
		include("./_tables.php");
		
		echo 
		'<div id="cpanel">';
				
		$dgv = new DataGridView($this);
		$dgv->deleteButton = false;
		$dgv->editButton = false;
		
		$dgv->OpenHeader();
		$dgv->AddHeader("vorname", "20%", true);
		$dgv->AddHeader("nachname", "20%", true);
		$dgv->AddHeader("week", "20%", true);
		$dgv->AddHeader("time", "20%", true);
		$dgv->AddHeader("time", "20%", true);
		$dgv->AddHeader("WeekDetail","",true);
		$dgv->CloseHeader();
		
		$res = $GLOBALS['db']->Query("
				SELECT * , SEC_TO_TIME(SUM( TIME_TO_SEC( TIMEDIFF( (SELECT CASE WHEN endTime IS NULL THEN NOW() ELSE endTime END), startTime ) ) ) - 10800) AS timeDiff, SEC_TO_TIME(SUM( TIME_TO_SEC( TIMEDIFF( (SELECT CASE WHEN endTime IS NULL THEN NOW() ELSE endTime END), startTime ) ) )) as timeD
				FROM ".$viewjobtimesweek."
				GROUP BY week");
		
		
		$count = 0;
		while($line = $GLOBALS['db']->Fetch($res))
		{
			$dgv->AddRow($line->id);
			$dgv->AddData($line->firstName, "", "", "firstName");
			$dgv->AddData($line->lastName, "", "", "lastName");
			$dgv->AddData($line->week, "", "", "week");
			$dgv->AddData($line->timeDiff, "", "", "timeDiff");
			$dgv->AddData($line->timeD, "", "", "timeD");
			$dgv->AddHidden("week".$line->id, $line->week);
			
			$img = '<img src="images/search.png" border="0" height="15px" width="15px" alt="showJob" 
							onmouseover="return overlib(\'Show Week\');" onmouseout="return nd();"/>';
			$dgv->AddMisc("", 'return ListItemTask(\'cb'.$count.'\',\'showWeek\');', $img);
			
			$dgv->CloseRow();
			$count++;
		}
		
		$dgv->CloseDataGrid();
		
		echo '</div>';
	}
	public function Toolbar()
	{	
		
	}
	public function AddCSS()
	{
			
	}
	public function AddJS()
	{
		
	}
}

?>